package com.qwfys.sample.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.qwfys.sample.jackson.model.ModuleDo;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.IOException;

public class JacksonApplication {

    public static void main(String[] args) throws IOException {

        String data = "{\"moduleName\":\"Account\",\"moduleTitle\":\"Add New Account\",\"moduleDescription\":\"Create new Account\",\"fields\":[{\"name\":\"name\",\"caption\":\"Enter User name\",\"type\":\"string\",\"formControl\":\"text\",\"required\":false,\"requiredMsg\":\"\"},{\"name\":\"password\",\"caption\":\"Enter password\",\"type\":\"string\",\"formControl\":\"password\",\"required\":false,\"requiredMsg\":\"\"}]}";
        ObjectMapper mapper = new ObjectMapper();
        ModuleDo module = mapper.readValue(data, ModuleDo.class);
        String toString = ReflectionToStringBuilder.toString(module, ToStringStyle.JSON_STYLE, true, true);
        System.out.println(toString);
    }

}
